<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class ZhidingController extends AdminbaseController {

	 //通告列表
	function tonggao_zhiding_lst(){
		$name = trim(I("name"));
		$nickname = trim(I("nickname"));
		$phone = trim(I("phone"));
		$stime = I("kaishi");
		$etime = I("jieshu");

		$p = I("p");
		$where = " 1 ";
		if(!empty($name)){
			$where .= " and t.name like '%{$name}%' ";
		}
		if(!empty($nickname)){
			$where .= " and a.nickname like '%{$nickname}%' ";
		}
		if(!empty($phone)){
			$where .= " and t.phone like '%{$phone}%' ";
		}
		if (!empty($stime)) {
			$time1 = strtotime($stime." "."00:00:00");
			$where .= " and {$time1} <= t.ctime";
		}
		if (!empty($etime)) {
			$time2 = strtotime($etime." "."23:59:59");
			$where .= " and t.ctime <= {$time2}";
		}

		$count = M("tonggao t")
			->join(" left  join " .C("DB_PREFIX") . "account a on t.account_id = a.id")
			->where($where)
			->count();


		if($count==0){
			$p = 0;
		}else{
			if(empty($p)){
				$p = 1;
			}
		}
		$totalpage = ceil($count/10);
		$page = $this->page($count,10);
		$sd = ($p-1)*10;
//               var_dump($stime);die;
		$data = M("tonggao t")
			->join(" left  join " .C("DB_PREFIX") . "account a on t.account_id = a.id")
			->where($where)
			->field("t.*,a.nickname")
			->limit($page->firstRow . ',' . $page->listRows)
			->order("case when t.is_paixu = 0 then 2 else 3 end desc,t.is_paixu asc,t.ctime desc")
			->select();



		$this->assign("data",$data);
		$this->assign("nickname",$nickname);
		$this->assign("name",$name);
		$this->assign("phone",$phone);
		$this->assign("stime_kaishi",$stime);
		$this->assign("etime_jieshu",$etime);
		$this->assign("page", $page->show('Admin'));
		$this->assign("p",$p);
		$this->assign("sd",$sd);
		$this->assign("totalpage",$totalpage);
		$this->display();
	}

	//排序
	function paixu(){
		$id = I("id");
		$shunxu = I("tonggao");
		M("tonggao")->where("is_paixu = $shunxu")->save(array('is_paixu'=>''));
		$data = M("tonggao")->where("id = $id")->save(array('is_paixu'=>$shunxu));
		if($data) {
			echo  1;
		}
	}





	//推荐列表
	function tuijian_zhiding_lst(){
		$nickname = trim(I("nickname"));
		$phone = trim(I("phone"));

		$p = I("p");
		$where = " 1 ";

		if(!empty($nickname)){
			$where .= " and a.nickname like '%{$nickname}%' ";
		}
		if(!empty($phone)){
			$where .= " and a.phone like '%{$phone}%' ";
		}


		$count = M("tuijian t")
			->join(" left  join " .C("DB_PREFIX") . "account a on t.account_id = a.id")
			->join(" left join " . C("DB_PREFIX") . "geren_lable gl on t.zhiye_lable_id = gl.id")
			->where($where)
			->count();


		if($count==0){
			$p = 0;
		}else{
			if(empty($p)){
				$p = 1;
			}
		}
		$totalpage = ceil($count/10);
		$page = $this->page($count,10);
		$sd = ($p-1)*10;
//               var_dump($stime);die;
		$data = M("tuijian t")
			->join(" left  join " .C("DB_PREFIX") . "account a on t.account_id = a.id")
			->join(" left join " . C("DB_PREFIX") . "geren_lable gl on t.zhiye_lable_id = gl.id")
			->where($where)
			->field("t.*,a.nickname,gl.lable,a.phone")
			->limit($page->firstRow . ',' . $page->listRows)
			->order("case when t.is_paixu = 0 then 2 else 3 end desc,t.is_paixu asc,t.ctime desc")
			->select();



		$this->assign("data",$data);
		$this->assign("nickname",$nickname);
		$this->assign("phone",$phone);
		$this->assign("page", $page->show('Admin'));
		$this->assign("p",$p);
		$this->assign("sd",$sd);
		$this->assign("totalpage",$totalpage);
		$this->display();
	}
	//推荐 置顶开关
	//排序
	function paixu2(){
		$id = I("id");
		$shunxu = I("tuijian");
		M("tuijian")->where("is_paixu = $shunxu")->save(array('is_paixu'=>''));
		$data = M("tuijian")->where("id = $id")->save(array('is_paixu'=>$shunxu));
		if($data) {
			echo  1;
		}
	}















}